package OfferAliBaBa.a_21年阿里笔试;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
3
4 4 3
2 3 4
5 2 6

 */
public class Main2 {
    static long mod = (long) Math.pow(10, 9) + 7;

    public static void main(String[] args) throws IOException {
        Main2 test = new Main2();
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int count = Integer.parseInt(reader.readLine());

        /*for (int i = 0; i < count; i++) {
            String[] split = reader.readLine().split(" ");

            long solve = test.solve(
                    Long.parseLong(split[0]) % mod,
                    Long.parseLong(split[1]) % mod,
                    Integer.parseInt(split[2])
            );

            System.out.println(solve);
        }*/

        for (int i = 0; i < count; i++) {
            String[] split = reader.readLine().split(" ");
            long result = test.fun1(
                    Integer.parseInt(split[2]),
                    Long.parseLong(split[0]) % mod,
                    Long.parseLong(split[1]) % mod
            );

            System.out.println(result);

        }
    }

    /**
     * @param n
     * @param A x + y
     * @param B x * y
     * @return
     */
    public long fun1(int n, long A, long B) {
        if (n == 1) {
            // return A % (1000000007);
            return A % mod;
        }
        if (n == 2) {
            // return (A + 2 * B)% (1000000007);
            return (A * A % mod - 2 * B % mod + mod) % mod;
        }

        return (A * fun1(n - 1, A, B) % mod - B * fun1(n - 2, A, B) % mod + mod) % mod;
    }

    public long solve(long a, long b, int n) {
        long[] nums = new long[n + 1];

        nums[1] = a;
        if (n == 1) {
            return nums[1];
        }

        nums[2] = (a * a % mod - 2 * b % mod + mod) % mod;
        if (n == 2) {
            return nums[2];
        }

        for (int i = 3; i <= n; i++) {
            nums[i] = ((a * nums[i - 1] % mod) - (b * nums[i - 2] % mod) + mod) % mod;
        }
        return nums[n];
    }
}
